package com.djx.基础;

import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;

public class ZKExists {

    ZooKeeper zooKeeper = new MyZookepper01().zooKeeper;

    @Test
    public void syncExists() throws KeeperException, InterruptedException {
        Stat stat = zooKeeper.exists("/djx", false);
        System.out.println("数据为 " + stat.getEphemeralOwner());
    }

    @Test
    public void asyncExists() throws KeeperException, InterruptedException {
        zooKeeper.exists("/djx", false, new AsyncCallback.StatCallback() {
            public void processResult(int i, String s, Object o, Stat stat) {
                System.out.println(i);
                System.out.println(s);
                System.out.println(o);
                System.out.println("数据为 " + stat);
            }
        }, "查询成功");
        Thread.sleep(30000);
        System.out.println("结束");
    }
}
